﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class NewsClass : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    AccessConn con = new AccessConn();
    DataSet ds;
    OleDbCommand comm;
    OleDbConnection conn;
    OleDbDataAdapter da;

    //分页
    public static int SJ_TotalRecord; //总共多少条记录
    public static int SJ_PageCount;   //总共多少页

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GetNewsDataBind();
        }
    }
   
    private void GetNewsDataBind()
    {
        string s2 = "select * from billInfo where id=1";
        DataSet ds2 = dao.getDs(s2);
        this.dlProdu.DataSource = ds2;
        this.dlProdu.DataBind();

        ds = new DataSet();
        conn = con.getConn();

        //aspNetPager控件分页
        string name = Request.QueryString["name"].ToString();
        string ss = "";
        if (name.Equals("新闻中心"))
        {
            //ss = "select * from zhengce,zhengceInfo  where zhengce.tyId=zhengceInfo.typeId and zhengce.tyId=zhengceInfo.typeId order by zhengce.id desc";
            ss = "select * from newMessage order by id desc";
        }
        else
        {
            ss = "select * from newMessage where typeName='" + name + "' order by id desc";

        }


        //创建分页类
        PagedDataSource objPage = new PagedDataSource();

        //设置数据源
        DataTable dataTable = null;

        conn.Open();
        da = new OleDbDataAdapter(ss, conn);

        da.Fill(ds, "Page");

        dataTable = ds.Tables["Page"];
        if (dataTable != null)
        {
            objPage.DataSource = dataTable.DefaultView;
        }


        //允许分页
        objPage.AllowPaging = true;
        //设置每页显示的项数
        objPage.PageSize = 15;

        SJ_TotalRecord = dataTable.Rows.Count;//总共多少条记录
        SJ_lblRecordCount.Text = dataTable.Rows.Count.ToString();

        SJ_PageCount = (SJ_TotalRecord + objPage.PageSize - 1) / objPage.PageSize;//总共多少页
        SJ_lblPageCount.Text = "共" + SJ_PageCount.ToString() + "页";


        //定义变量用来保存当前页索引
        int CurPage;
        //判断是否具有页面跳转的请求
        if (Request.QueryString["Page"] != null)
            CurPage = Convert.ToInt32(Request.QueryString["Page"]);
        else
            CurPage = 1;
        //设置当前页的索引
        objPage.CurrentPageIndex = CurPage - 1;

        //显示状态信息
        SJ_lblCurPage.Text = "当前页：第" + CurPage.ToString() + "页";

        //如果当前页面不是首页
        if (!objPage.IsFirstPage)
        {
            //定义"上一页"超级链接的URL为：当前执行页面的虚拟路径,并传递下一页面的索引值
            SJ_lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
            SJ_lnkPrev.NavigateUrl += "&ID=" + ID;
            SJ_lnkPrev.NavigateUrl += "&name=" + name;

        }
        //如果当前页面不是最后一页
        if (!objPage.IsLastPage)
        {
            //定义"下一页"超级链接的URL为：当前执行页面的虚拟路径,并传递下一页面的索引值
            SJ_lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
            SJ_lnkNext.NavigateUrl += "&ID=" + ID;
            SJ_lnkNext.NavigateUrl += "&name=" + name;
        }

        SJ_FistPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
        SJ_FistPage.NavigateUrl += "&ID=" + ID;
        SJ_FistPage.NavigateUrl += "&name=" + name;

        SJ_EndPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + SJ_PageCount;
        SJ_EndPage.NavigateUrl += "&ID=" + ID;
        SJ_EndPage.NavigateUrl += "&name=" + name;

        //进行数据绑定
        Datalist2.DataSource = objPage;
        Datalist2.DataBind();
    }

}
